package com.flink.datastreamapi.partition;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class PartitionExample {
    public static void main(String[] args) throws Exception {


        ///获取环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        //设置并行度
        env.setParallelism(2);
        //读取数据源
        DataStreamSource<String> stream = env.socketTextStream("10.90.100.102", 8888);


        //分区

        //随机分区
        //stream.shuffle()
        //轮询分区
       // stream.rebalance()
        //实现轮询，局部组队，比rebalance更高效
       // stream.rescale()
        //发送给下游的所有子任务
        //stream.broadcast()
        //全部发往第一个子任务
        stream.global()
        //输出
         .print();
        //执行
        env.execute();
    }
}
